﻿using System;
using System.Web.UI.WebControls;
using Ue.Framework.Web;
using Ue.Infrastructure.DomainBase;
using Ue.Infrastructure.RepositoryFramework;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.SinglePages;
namespace Ue.Qcdz.UI.Controls
{
    public class SinglePageGridView : SkinnedGridView, ISinglePageDataQuery, ISort
    {

        private ISinglePageRepository repository;

        public SinglePageGridView()
        {
            this.repository = RepositoryFactory.GetRepository<ISinglePageRepository, SinglePage>();
        }

        protected override void GridViewDataBind(object sender, EventArgs args)
        {
            IDataResult<SinglePage> dataResult = this.repository.FindBy(this);
            this.RecordCount = dataResult.RecordCount;

            Repeater repeater = sender as Repeater;
            repeater.DataSource = dataResult.DataObjects;
            repeater.DataBind();
        }

        protected override string GetSkinFileName()
        {
            return "~/Admin/Themes/Skins/SinglePages/SinglePages.ascx";
        }

        #region ISinglePageDataQuery 成员

        public bool Status
        {
            get;
            set;
        }


        public string CategoryId
        {
            get
            {
                string keyId = Page.Request.GetQueryValue<string>("ctId");
                if (string.IsNullOrEmpty(keyId))
                    return SinglePageType.GetSinglePageKey(PageType);
                else
                    return keyId;
            }
        }
        #endregion



        #region ISort 成员

        public string BuildSortStatement()
        {
            return "DisplayOrder desc";
        }

        #endregion

        public SinglePageType.SgPage PageType
        {
            set;
            get;
        }
        public override ISort Sort
        {
            get
            {
                return this;
            }
            protected set
            {
                base.Sort = value;
            }
        }
    }
}
